<template>
  <div>
    <table class="table table-sm table-bordered approve-table">
      <colgroup>
        <col width="20%" />
        <col width="30%" />
        <col width="20%" />
        <col width="30%" />
      </colgroup>
      <tbody>
        <tr>
          <td>风险审查附件</td>
          <td colspan="3" class="text-left">
            <attach-main
              :related-id="relatedId"
              @status="handleAttachSuccess"
              :viewMode="isView"
            ></attach-main>
          </td>
        </tr>
      </tbody>
    </table>
    <approve-common
      v-bind="$attrs"
      v-on="$listeners"
      :view-mode="isView"
      :related-data="relatedData"
      :approve-data="approveData"
      :before-save="submit"
      @success="handleSuccess"
    ></approve-common>
  </div>
</template>

<script>
import ApproveCommon from '@/credit/views/county/unionProvince/components/projectApprove/ApproveCommon'
import AttachMain from '@/credit/views/county/unionProvince/components/projectApprove/components/risk/AttachMain'
export default {
  components: {
    AttachMain,
    ApproveCommon,
  },
  props: {
    relatedData: {
      type: Object,
      default: () => ({}),
    },
    approveData: {
      type: Object,
      default: () => ({
        editable: false,
        record: [],
      }),
    },
    viewMode: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      attachFinished: false,
    }
  },
  computed: {
    relatedId() {
      return this.relatedData.customer_related_id
    },
    isView() {
      return this.viewMode || !this.approveData.editable
    },
  },
  watch: {},
  created() {},
  mounted() {},
  methods: {
    handleAttachSuccess(status) {
      this.attachFinished = +status === 1
    },
    submit() {
      if (!this.attachFinished) {
        return this.$message.warning('请完善风险审查附件')
      }
      return true
    },
    handleSuccess(res) {
      this.$emit('success', res)
    },
  },
}
</script>

<style lang="scss" scoped>
@import './index.scss';
</style>
